package com.example.luke.cashorderingsystem.Dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;

import com.example.luke.cashorderingsystem.Common.Setting;
import com.example.luke.cashorderingsystem.R;
import com.example.luke.cashorderingsystem.Util.GlobalFunction;

import java.util.ArrayList;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;

/**
 * Created by luke on 25/11/2016.
 */

public class DevIdDialog extends Dialog {

    public  interface  DialogListener{

        void optionSelected(String option);

    }

    @InjectView(R.id.devNo)EditText devNo;

    @InjectView(R.id.addDevId)Button addDevId;

    private ArrayList<String> itemList;
   private LayoutInflater inflater;
    private DialogListener dialogListener;

   private Context context;
    String currentDevNo;



    public DevIdDialog(String currentDevNo,Context context){
        super(context);
          this.context=context;
        inflater=LayoutInflater.from(context);

        requestWindowFeature(Window.FEATURE_NO_TITLE);
        this.currentDevNo=currentDevNo;


    }

    public void setDialogListener(DialogListener dialogListener) {
        this.dialogListener = dialogListener;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dev_id_dialog_layout);
        ButterKnife.inject(this);

    devNo.setText(this.currentDevNo);

    }



    @OnClick(R.id.addDevId)
    void saveDevNo(){

        if (devNo.getText().length()>0){
            if (dialogListener!=null){
                dialogListener.optionSelected(devNo.getText().toString());
            }
            dismiss();
            GlobalFunction.ToastAlert(context,"保存成功");
        }
        else {

            GlobalFunction.ToastAlert(context,"请输入机号");
        }
    }




}
